package com.lineage.server.serverpackets;

import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;

public class S_ChatGlobal extends ServerBasePacket {
  private byte[] _byte;
  
  public S_ChatGlobal(L1PcInstance pc, String chat) {
    this._byte = null;
    buildPacket(pc, chat);
  }
  
  private void buildPacket(L1PcInstance pc, String chat) {
    writeC(243);
    writeC(3);
    if (pc.isGm()) {
      writeS("[******] " + chat);
    } else if (pc.isProtector()) {
      writeS("\\aD[**守护者**] " + chat);
    } else {
      writeS("[" + pc.getName() + "] " + chat);
    } 
  }
  
  public S_ChatGlobal(L1NpcInstance npc, String chat) {
    this._byte = null;
    writeC(243);
    writeC(3);
    writeS("[" + npc.getNameId() + "] " + chat);
  }
  
  public S_ChatGlobal(String chat) {
    this._byte = null;
    writeC(243);
    writeC(3);
    writeS(chat);
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
